﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using DBUtility;
using IDAL;
using Model;

namespace DAL
{
    class PackageProduct_QT:IPackageProduct_QT
    {
        #region 静态变量部分
        private const string PARM_TEST_CUSTOMERNAME = "@CustomerName";
        private const string PARM_TEST_PRODUCTTYPEIDS = "@ProductTypeIDs";
        private const string PARM_TEST_STARTTIME = "@starttime";
        private const string PARM_TEST_STOPTIME = "@stoptime";
        #endregion

        #region 数据检索部分
        public IList<Time_QInfo> GetProductType_QT(string customerName,DateTime starttime, DateTime stoptime)
        {
            IList<Time_QInfo> pt_qs = new List<Time_QInfo>();
            SqlParameter[] testParms = GetParameters();
            testParms[0].Value = customerName;
            testParms[1].Value = starttime;
            testParms[2].Value = stoptime;

            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "PackageTest_countbyTimeD_CustDT", testParms))
            {
                while (rdr.Read())
                {
                    Time_QInfo pt_q = new Time_QInfo(rdr.GetValue(0).ToString(), rdr.GetInt32(1));
                    pt_qs.Add(pt_q);
                }
            }
            return pt_qs;
        }

        public IList<ProductType_QInfo> GetAllPID_QT(string productTypeIDs, DateTime starttime, DateTime stoptime)
        {
            IList<ProductType_QInfo> pt_qs = new List<ProductType_QInfo>();
            SqlParameter[] testParms = GetDTParameters();
            testParms[0].Value = productTypeIDs;
            testParms[1].Value = starttime;
            testParms[2].Value = stoptime;

            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "PackageTest_countbyTimeD_ALLPIDDT", testParms))
            {
                while (rdr.Read())
                {
                    ProductType_QInfo pt_q = new ProductType_QInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString(), rdr.GetValue(2).ToString(), rdr.GetInt32(3));
                    pt_qs.Add(pt_q);
                }
            }
            return pt_qs;
        }

        public DataSet GetAllPID_QT1(string productTypeIDs, DateTime starttime, DateTime stoptime)
        {
            {
                DataSet ds = new DataSet();
                SqlParameter[] testParms = GetDTParameters();
                testParms[0].Value = productTypeIDs;
                testParms[1].Value = starttime;
                testParms[2].Value = stoptime;

                ds = sqlHelper.GetDataSet("PackageTest_countbyTimeD_ALLPIDDT1", "PackageQ", sqlHelper.ConnectionStringLocalTransaction, testParms);
                return ds;
            }
        }
        #endregion

        #region 参数部分
        private static SqlParameter[] GetDTParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
                    new SqlParameter(PARM_TEST_PRODUCTTYPEIDS,SqlDbType.NVarChar,500),
					new SqlParameter(PARM_TEST_STARTTIME, SqlDbType.DateTime, 8),
                    new SqlParameter(PARM_TEST_STOPTIME, SqlDbType.DateTime, 8)   
                };
            return parms;
        }

        private static SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
                    new SqlParameter(PARM_TEST_CUSTOMERNAME,SqlDbType.NVarChar,50),
					new SqlParameter(PARM_TEST_STARTTIME, SqlDbType.DateTime, 8),
                    new SqlParameter(PARM_TEST_STOPTIME, SqlDbType.DateTime, 8)   
                };
            return parms;
        }
        #endregion
    }
}
